package com.android.monee.data.access.inMemory;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.android.monee.data.model.Budget;
import com.android.monee.data.model.Budget.BudgetState;
import com.android.monee.data.model.Mensuality;
//import com.android.monee.data.model.Mensuality.MensualityState;
import com.android.monee.domain.BudgetService;
import com.android.monee.domain.MensNbCalc;
import com.android.monee.domain.MensNbCalcFactory;

public class InMemoryMockDatas {

	public static List<Budget> getMockBudgetList(){
		List<Budget> budgets = new ArrayList<Budget>();
		 
		for(int i = 1 ; i < 10 ; i++){
			Calendar cal = Calendar.getInstance();
		
			//cal.add(Calendar.MONTH, -(i%3));
			cal.add(Calendar.MONTH, -i%5);
			Date begin = cal.getTime();
			
			//cal.add(Calendar.MONTH, i+2);
			cal.add(Calendar.MONTH, i+2  + (i%5));
			Date term = cal.getTime();
			Budget budget = new Budget();
			budget.setName("Budget numéro " + i);
			budget.setBegin(begin);
			budget.setTerm(term);
			
			MensNbCalc calc = MensNbCalcFactory.getMensNbCalc();
			budget.setTotalAmount(i * 100);
			budget.setInitialAmount(Math.round(budget.getTotalAmount()/calc.getNbMensuality(budget) * (i % 5)));
			budget.setState(BudgetState.RUNNING);
			
			budgets.add(budget);
		}
		
		return budgets;
	}
	
	public static List<Mensuality> getMockMensualityDoneList(Budget budget){
		List<Mensuality> res = new ArrayList<Mensuality>();

		MensNbCalc calc = MensNbCalcFactory.getMensNbCalc();
		Calendar cal = Calendar.getInstance();
		
		int nbTotMens = calc.getNbMensuality(budget);
		
		int nbMensDone = Math.round(budget.getInitialAmount()/budget.getTotalAmount()*nbTotMens); 
		
		//System.out.println("Compute done mensualities for budget "+budget.getName());
		
		for (int i = 1 ; i <= nbMensDone ; i++){
			Mensuality mens = new Mensuality(budget);
			mens.setAmount(budget.getTotalAmount()/nbTotMens);
			mens.setBudgetId(budget.getId());
			mens.setNumber(i);
			BudgetService budgetService = new BudgetService(budget);
			mens.setDate(budgetService.getDateForMensuality(i)); 
			mens.setDone(true);//State(MensualityState.DONE);
			mens.setCancelled(false);
			
			///System.out.println("Add mensuality "+mens.getDate()+ " " + mens.getAmount());
			res.add(mens);
		}
		return res;
	}
}
